/**
 * Created by aurogon-mac on 15/4/25.
 */
var http = require("http");
var url = require("url");

function start(route, handle) {

    function onRequest(request, response) {
        var postData = "";
        var pathname = url.parse(request.url).pathname;
        console.log("Request for " + pathname + " received.");

        //request.setEncoding("utf-8");

        //request.addListener("data", function(postDataChunk){
        //    postData += postDataChunk;
        //    console.log("Received POST data chunk '" + postDataChunk + "'.");
        //});

        //request.addListener("end", function () {
        //    route(handle, pathname, response, postData, request);
        //});

        route(handle, pathname, response, postData, request);
    }

    http.createServer(onRequest).listen(8888);
    console.log("Server has been started");
}

exports.start = start;